package thread.java20230113;

/**
 * 死锁演示
 */
public class Demo56 {
    public static void main(String[] args) {
        Object o1 = new Object();
        Object o2 = new Object();
        Thread t1 = new Thread(()->{
           synchronized (o1){
               try {
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
               synchronized (o2){
                   System.out.println("t1 执行");
               }
           }
        });

        Thread t2 = new Thread(()->{
            synchronized (o1){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (o2){
                    System.out.println("t2 执行");
                }
            }
        });

        t1.start();
        t2.start();
    }
}
